'''
import urllib.request
import urllib.parse
import json

content=input('what do you wanna translate?')

url='http://fanyi.youdao.com/translate?smartresult=dict&smartresult=rule&smartresult=ugc&sessionFrom=https://www.baidu.com/link'
#Request URL:http://fanyi.youdao.com/translate_o?smartresult=dict&smartresult=rule&sessionFrom=https://www.baidu.com/link
data={}

data['type']='AUTO'
data['i']=content
data['doctype']='json'
data['xmlVersion']='1.8'
data['keyfrom']='fanyi.web'
data['ue']='UTF-8'
data['action']='FY_BY_CLICKBUTTON'
data['typoResult']='true'
data=urllib.parse.urlencode(data).encode('UTF-8')

respond = urllib.request.urlopen(url,data)
html=respond.read().decode('utf-8')

target=json.loads(html)
print('result:%s'%(target['translateResult'][0][0]['tgt']))
'''


import urllib.request
import urllib.parse
import json

content = input('请输入需要翻译的内容：')

url = 'http://fanyi.youdao.com/translate?smartresult=dict&smartresult=rule&sessionFrom=https://www.baidu.com/link'
#Request URL:http://fanyi.youdao.com/translate_o?smartresult=dict&smartresult=rule&sessionFrom=https://www.baidu.com/link

data = {}
data['i'] = content
data['from'] = 'AUTO'
data['to']='AUTO'
data['smartresult'] = 'dict'
data['client'] = 'fanyideskweb'
data['salt'] = '1499309679092'
data['sign'] = '44aca364ec05443a49825bc4de3a9809'
data['doctype'] = 'json'
data['version'] = '2.1'
data['Keyfrom'] = 'fanyi.web'
data['action']='FY_BY_CLICKBUTTON'
data['typoResult'] = 'true'
data = urllib.parse.urlencode(data).encode('UTF-8')

respond = urllib.request.urlopen(url,data)
html = respond.read().decode('utf-8')

target = json.loads(html)
print('翻译结果为：%s'%(target['translateResult'][0][0]['tgt']))

